package com.mhc.suzuki.controller;

import com.mhc.haval.security.model.User;
import com.mhc.suzuki.constant.ErrorCodeEnum;
import com.mhc.suzuki.service.ModificationService;
import com.subaru.common.entity.BizResult;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by HW
 * on 2017/9/4 15:12.
 */
@Slf4j
@Controller
@RequestMapping(value = "/modification")
public class ModificationController {


    @Autowired
    private ModificationService modificationService;

    /**
     * 互换购车人接口
     * @param orderNo
     * @param reason
     * @return
     */
    @ApiOperation(value = "互换购车人", notes = "互换购车人")
    @RequestMapping(value = "/buyerReplacement/{orderNo}", method = RequestMethod.POST)
    public @ResponseBody BizResult exchangeBuyer (@PathVariable String orderNo, String reason, @AuthenticationPrincipal User user){
        if(StringUtils.isNotBlank(orderNo) && modificationService.buyerReplacement(orderNo, reason, user)){
              return BizResult.create(Boolean.TRUE, true, ErrorCodeEnum.SUCCESS.getErrCode(), ErrorCodeEnum.SUCCESS.getErrMsg());
        }
        return BizResult.create(ErrorCodeEnum.PARAM_ERROR.getErrCode(), ErrorCodeEnum.PARAM_ERROR.getErrMsg());
    }

}
